//
//  ZLMoreBaseViewController.m
//  EnjoyAll
//
//  Created by 王晓冰 on 2017/10/30.
//  Copyright © 2017年 张雷. All rights reserved.
//

#import "ZLMoreBaseViewController.h"

@interface ZLMoreBaseViewController ()

@end

@implementation ZLMoreBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self _initBackButton];
    _selectIndex = 0;
}

- (void)_initBackButton {
    
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
    
    UIControl *backCtrl = [[UIControl alloc]initWithFrame:CGRectMake(0, 0, 44, 44)];
   
    UIImageView *backImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, (44-KSHeight(34))*0.5, KSWidth(19), KSHeight(34))];
    backImageView.image = [UIImage imageNamed:@"back.png"];
    [backCtrl addSubview:backImageView];
    
    [backCtrl addTarget:self action:@selector(backButtonAction) forControlEvents:UIControlEventTouchUpInside];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backCtrl];
}

- (void)backButtonAction {
    
    [self.navigationController popViewControllerAnimated:YES];
    
}

- (void)setChildsCtrl:(NSArray *)childsCtrl {
    _childsCtrl = childsCtrl;
    
    for (UIViewController *ctrl in _childsCtrl) {
        [self addChildViewController:ctrl];
    }
    
    if (self.childViewControllers.count > 0) {
        
        UIView *subView = self.childViewControllers[0].view;
        [self.view addSubview:subView];
    }
}

- (void)setSelectIndex:(NSInteger)selectIndex {
    
    [self transitionFromViewController:self.childViewControllers[_selectIndex] toViewController:self.childViewControllers[selectIndex] duration:0 options:UIViewAnimationOptionLayoutSubviews animations:nil completion:nil];
    
    _selectIndex = selectIndex;
    
}

- (void)viewWillDisappear:(BOOL)animated {
    
    [super viewWillDisappear:animated];
    
    [self.view endEditing:YES];
}


//结束编辑
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
    [self.view endEditing:YES];
}

@end
